package br.ufrj.neg.usuario.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import br.ufrj.neg.constants.General;


public class LogoffAction extends HttpServlet {
	
	private static final long serialVersionUID = 8326133989618899803L;
	//private static Logger log = Logger.getLogger("rootLogger");

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		try {
			/*
			 * Tratando a sessão
			 */
			HttpSession session = request.getSession();

			/*
			 * Matando a sessão
			 */
			synchronized (session) {
				session.setAttribute("logado", false);
				session.invalidate();
			}
			/*response.sendRedirect("http://www.negociacao.net/br/index3.html");*/
			response.sendRedirect(General.APP_PATH);
		} catch (Exception e) {
			System.out.println(e);
			request.getRequestDispatcher(General.TELA_ERRO_500).forward(request,
					response);
		}

	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		doPost(request, response);
	}
}
